﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace EEDS.Core
{
    public class Emblem 
    {
        private Bitmap image;
        private Palette palette;

        public Emblem(Bitmap image, Palette palette)
        {
            if (image.Size.Width != 32 || image.Size.Height != 32)
                throw new NotSupportedException("Emblems must be 32x32 pixels in size.");
            if (!palette.ConfirmMatch(image))
                throw new NotSupportedException("The palette does not match the source image.");

            this.image = Util.ConvertImagePalette(image, palette);
            this.palette = palette;
        }

        public void ConvertToPalette(Palette newPalette, PaletteConverter converter)
        {
            converter.ConvertToPalette(this.Image, this.Image, newPalette);

            this.palette = newPalette;
        }

        public static Emblem FromImage(Bitmap image)
        {
            return null;
        }

        public static Emblem FromImage(Bitmap image, Rectangle rect)
        {
            return FromImage(image.Clone(rect, image.PixelFormat));
        }

        public static Emblem FromImage(Bitmap image, Rectangle rect, Palette palette)
        {
            return new Emblem(image.Clone(rect, image.PixelFormat), palette);
        }

        public Bitmap Image
        {
            get
            {
                return image;
            }
        }

        public Palette Palette
        {
            get
            {
                return palette;
            }
        }

        public Game Game
        {
            get
            {
                return Palette.Game;
            }
        }
    }
}
